package com.promis.party.preference;

import android.content.Context;

import com.promis.SharedPreferencesHolder;
import com.promis.util.DateUtils;
import com.promis.util.StringUtils;

import java.util.Date;

/**
 * Created by zengyuwen on 2017/9/4.
 *
 */

public class UserPreferences extends SharedPreferencesHolder {

    private static UserPreferences preference = null;

    private final static String USER_ID = "userId";
    private final static String USER_NAME = "userName";
    private final static String USER_PHONE = "userName";
    private final static String USER_HEADER = "userHeader";
    private final static String USER_COVER = "userCover";
    private final static String USER_SIGN = "userSign";
    private final static String USER_REALNAME = "userRealname";
    private final static String USER_IDCARDNAME = "userIdCardName";
    private final static String USER_LISCANCENAME = "userLiscenceName";
    private final static String USER_SEX = "userSex";
    private final static String USER_BIRTHDAY = "userBirthday";
    private final static String USER_FOLLOWUSERCOUNT = "followUserCount";
    private final static String USER_FOLLOWTOPICCOUNT  = "followTopicCount";
    private final static String USER_FANSCOUNT  = "fansCount";
    private final static String USER_PETSCOUNT  = "petsCount";
    private final static String USER_STORESCOUNT  = "storesCount";
    private final static String USER_GOODSCOUNT  = "goodsCount";
    private final static String USER_MYDYNAMICCOUNT  = "myDynamicCount";
    private final static String USER_ADOPTDYNAMICCOUNT  = "adoptDynamicCount";
    private final static String USER_ISEMPLOYEE  = "isStoreEmployee";
    private final static String USER_STOREID  = "storeId";
    private final static String USER_STORENAME  = "storeName";

    private final static String USER_SYSTEM_MASSAGE  = "systemMassageLooking";
    private final static String USER_ANSWER_MASSAGE  = "answerMassageLooking";
    private final static String USER_EVALUATE_MASSAGE  = "evaluateMassageLooking";
    private final static String USER_PRISE_MASSAGE  = "priseMassageLooking";
    private final static String USER_REMIND_MASSAGE  = "remindMassageLooking";

    private final static String AUTH_TYPE = "authType";

    protected UserPreferences(Context context) {
        super(context);
    }

    public static synchronized UserPreferences getInstance(Context context){
        if(preference == null)
            preference = new UserPreferences(context);
        return preference;
    }

//    public void put(User user) {
//
//        editor.putString(USER_ID, user.getId());
//        editor.putString(USER_PHONE, user.getAccount());
//        editor.putString(USER_NAME, user.getName());
//        editor.putString(USER_HEADER, user.getImgHeader());
//        editor.putString(USER_COVER, user.getImgCover());
//        editor.putString(USER_SIGN, user.getSign());
//        editor.putString(USER_REALNAME, user.getRealname());
//        editor.putString(USER_IDCARDNAME, user.getIdCardName());
//        editor.putString(USER_LISCANCENAME, user.getLiscenseName());
//        if(user.getBirthday() != null){
//            String brithday = DateUtils.format(user.getBirthday(), "yyyy-MM-dd");
//            editor.putString(USER_BIRTHDAY, brithday);
//        }else{
//            editor.putString(USER_BIRTHDAY, "");
//        }
//        editor.putInt(USER_SEX, user.getSex());
//        editor.putInt(AUTH_TYPE, user.getAuthType());
//        editor.putInt(USER_FOLLOWUSERCOUNT, user.getFollowUserCount());
//        editor.putInt(USER_FOLLOWTOPICCOUNT, user.getFollowTopicCount());
//        editor.putInt(USER_FANSCOUNT, user.getFansCount());
//        editor.putInt(USER_PETSCOUNT, user.getPetsCount());
//        editor.putInt(USER_STORESCOUNT, user.getStoresCount());
//        editor.putInt(USER_GOODSCOUNT, user.getGoodsCount());
//        editor.putInt(USER_MYDYNAMICCOUNT, user.getMyDynamicCount());
//        editor.putInt(USER_ADOPTDYNAMICCOUNT, user.getAdoptDynamicCount());
//        editor.putInt(USER_ISEMPLOYEE, user.getIsStoreEmployee());
//        editor.putString(USER_STOREID, user.getStoreId());
//        editor.putString(USER_STORENAME, user.getStoreName());
//        editor.putInt(USER_SYSTEM_MASSAGE, user.getSystemMassageLooking());
//        editor.putInt(USER_ANSWER_MASSAGE, user.getAnswerMassageLooking());
//        editor.putInt(USER_EVALUATE_MASSAGE, user.getEvaluateMassageLooking());
//        editor.putInt(USER_PRISE_MASSAGE, user.getPriseMassageLooking());
//        editor.putInt(USER_REMIND_MASSAGE, user.getRemindMassageLooking());
//
//        editor.commit(); // 提交修改
//    }

    public void put(int systemCount, int answerCount, int evaluateCount, int priseCount, int remindCounts) {
        editor.putInt(USER_SYSTEM_MASSAGE, systemCount);
        editor.putInt(USER_ANSWER_MASSAGE, answerCount);
        editor.putInt(USER_EVALUATE_MASSAGE, evaluateCount);
        editor.putInt(USER_PRISE_MASSAGE, priseCount);
        editor.putInt(USER_REMIND_MASSAGE, remindCounts);

        editor.commit(); // 提交修改
    }

    public void put(int myDynamicCount, int adoptDynamicCount) {
        editor.putInt(USER_MYDYNAMICCOUNT, myDynamicCount);
        editor.putInt(USER_ADOPTDYNAMICCOUNT, adoptDynamicCount);

        editor.commit(); // 提交修改
    }

//    public void putCollectionCount(User user) {
//        editor.putInt(USER_FOLLOWUSERCOUNT, user.getFollowUserCount());
//        editor.putInt(USER_FOLLOWTOPICCOUNT, user.getFollowTopicCount());
//        editor.putInt(USER_FANSCOUNT, user.getFansCount());
//        editor.putInt(USER_PETSCOUNT, user.getPetsCount());
//        editor.putInt(USER_STORESCOUNT, user.getStoresCount());
//        editor.putInt(USER_GOODSCOUNT, user.getGoodsCount());
//
//        editor.commit(); // 提交修改
//    }

    public void putRealname(String realname) {
        editor.putString(USER_REALNAME, realname);
        editor.commit(); // 提交修改
    }

    public void putIdCardName(String realname) {
        editor.putString(USER_IDCARDNAME, realname);
        editor.commit(); // 提交修改
    }

    public void putLiscenceName(String realname) {
        editor.putString(USER_LISCANCENAME, realname);
        editor.commit(); // 提交修改
    }

    //修改领养动态数量
    public void putAdoptCount(int count) {
        editor.putInt(USER_ADOPTDYNAMICCOUNT, count);
        editor.commit(); // 提交修改
    }

    public void putSex(int sex) {
        editor.putInt(USER_SEX, sex);
        editor.commit(); // 提交修改
    }

    public void putCover(String cover) {
        editor.putString(USER_COVER, String.valueOf(cover));
        editor.commit(); // 提交修改
    }

    public void putSign(String sign) {
        editor.putString(USER_SIGN, String.valueOf(sign));
        editor.commit(); // 提交修改
    }

    public void putBirthday(Date birthday) {
        if(birthday == null) return;
        editor.putString(USER_BIRTHDAY, DateUtils.format(birthday, "yyyy-MM-dd"));
        editor.commit(); // 提交修改
    }

    public void putAuthType(int authType) {
        editor.remove(AUTH_TYPE);
        editor.putInt(AUTH_TYPE, authType);
        editor.commit(); // 提交修改
    }

    public boolean exists() {
        return !StringUtils.isNullOrEmpty(getId());
    }

    public void remove() {
        editor.remove(USER_ID);
        editor.remove(USER_NAME);
        editor.remove(USER_PHONE);
        editor.remove(USER_HEADER);
        editor.remove(USER_COVER);
        editor.remove(USER_SIGN);
        editor.remove(USER_REALNAME);
        editor.remove(USER_SEX);
        editor.remove(USER_BIRTHDAY);
        editor.remove(AUTH_TYPE);
        editor.remove(USER_FOLLOWUSERCOUNT);
        editor.remove(USER_FOLLOWTOPICCOUNT);
        editor.remove(USER_FANSCOUNT);
        editor.remove(USER_PETSCOUNT);
        editor.remove(USER_STORESCOUNT);
        editor.remove(USER_GOODSCOUNT);
        editor.remove(USER_MYDYNAMICCOUNT);
        editor.remove(USER_ADOPTDYNAMICCOUNT);
        editor.remove(USER_ISEMPLOYEE);
        editor.remove(USER_STOREID);
        editor.remove(USER_SYSTEM_MASSAGE);
        editor.remove(USER_ANSWER_MASSAGE);
        editor.remove(USER_EVALUATE_MASSAGE);
        editor.remove(USER_PRISE_MASSAGE);
        editor.remove(USER_REMIND_MASSAGE);
        editor.remove(USER_IDCARDNAME);
        editor.remove(USER_LISCANCENAME);
        editor.remove(USER_STORENAME);
        editor.commit();
    }

    public String getstoreId() {
        return sharedPreference.getString(USER_STOREID, "");
    }

    public int getIsEmployee() {
        return sharedPreference.getInt(USER_ISEMPLOYEE, 0);
    }

    public String getId() {
        return sharedPreference.getString(USER_ID, "");
    }

    public String getName() {
        return sharedPreference.getString(USER_NAME, "");
    }

    public String getPhone() {
        return sharedPreference.getString(USER_PHONE, "");
    }

    public String getImgHeader() {
        return sharedPreference.getString(USER_HEADER, "");
    }

    public String getImgCover() {
        return sharedPreference.getString(USER_COVER, "");
    }

    public String getRealname() {
        return sharedPreference.getString(USER_REALNAME, "");
    }

    public String getIdCardName() {
        return sharedPreference.getString(USER_IDCARDNAME, "");
    }

    public String getLiscenceName() {
        return sharedPreference.getString(USER_LISCANCENAME, "");
    }

    public String getStoreName() {
        return sharedPreference.getString(USER_STORENAME, "");
    }

    public String getBirthday() {
        return sharedPreference.getString(USER_BIRTHDAY, "");
    }

    public int getSex() {
        return sharedPreference.getInt(USER_SEX, 0);
    }

//    public int getAuthType() {
//        return sharedPreference.getInt(AUTH_TYPE, AuthType.NONE.getValue());
//    }

    public String getSign(){
        return sharedPreference.getString(USER_SIGN,"");
    }

    public int getFollowUserCount() {
        return sharedPreference.getInt(USER_FOLLOWUSERCOUNT, 0);
    }

    public int getFollowTopicCount() {
        return sharedPreference.getInt(USER_FOLLOWTOPICCOUNT, 0);
    }

    public int getFansCount() {
        return sharedPreference.getInt(USER_FANSCOUNT, 0);
    }

    public int getPetsCount() {
        return sharedPreference.getInt(USER_PETSCOUNT, 0);
    }

    public int getStoresCount() {
        return sharedPreference.getInt(USER_STORESCOUNT, 0);
    }

    public int getGoodsCount() {
        return sharedPreference.getInt(USER_GOODSCOUNT, 0);
    }

    public int getMyDynamic() {
        return sharedPreference.getInt(USER_MYDYNAMICCOUNT, 0);
    }

    public int getAdoptDynamic() {
        return sharedPreference.getInt(USER_ADOPTDYNAMICCOUNT, 0);
    }

    public int getSystemCount() {
        return sharedPreference.getInt(USER_SYSTEM_MASSAGE, 0);
    }

    public int getAnswerCount() {
        return sharedPreference.getInt(USER_ANSWER_MASSAGE, 0);
    }

    public int getEvaluateCount() {
        return sharedPreference.getInt(USER_EVALUATE_MASSAGE, 0);
    }

    public int getPriseCount() {
        return sharedPreference.getInt(USER_PRISE_MASSAGE, 0);
    }

    public int getRemindCount() {
        return sharedPreference.getInt(USER_REMIND_MASSAGE, 0);
    }
}
